package cn.com.taiji.pos.mapper;

import cn.com.taiji.pos.entity.MenuFoodItem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 菜品(品项)信息 Mapper 接口
 * </p>
 *
 * @author
 * @since 2021-03-01
 */
public interface MenuFoodItemMapper extends BaseMapper<MenuFoodItem> {


    @Select("select a.NAME_ZH,a.NAME_EN,b.PRICE as prices ,a.ID,b.ID as priceId " +
            "FROM menu_food_category mfc inner join menu_food_item A on mfc.ID=A.FOOD_CATEGORY_ID " +
            "left join MENU_FOOD_PRICE B on A.ID=B.FOOD_ID " +
            "where #{nowTime} between (b.START_TIME and b.END_TIME) and B.STATUS<>1 and A.STATUS<>1  " +
            "and (A.BAR_CODE like CONCAT('%',#{barCode},'%') or a.NAME_ZH like #{barCode} or a.NAME_EN like #{barCode} ) and mfc.CODE = #{code}")
    List<MenuFoodItem> listXMBFood(@Param("nowTime") String nowTime, @Param("barCode") String barCode, @Param("code") String code);

    @Select("SELECT * from ( select a.NAME_ZH,a.NAME_EN,b.PRICE as prices ,a.ID,b.ID as priceId,b.BUSINESS_TYPE_ID as businessTypeId,mfc.id as foodCategoryId " +
            "FROM menu_food_category mfc inner join menu_food_item A on mfc.ID=A.FOOD_CATEGORY_ID " +
            "left join MENU_FOOD_PRICE B on A.ID=B.FOOD_ID " +
            "left join CONFIG_MEAL_TIME c on B.MEAL_TIME_ID = c.ID " +
            "left join CONFIG_BUSINESS_TYPE d on b.BUSINESS_TYPE_ID=d.ID " +
            "where mfc.CODE<> #{mfcCode} and (c.NAME= #{canci} or c.Name='全天餐次' ) and (b.START_TIME<= #{nowTime} and b.END_TIME>= #{nowTime}) and B.STATUS<>1 and A.STATUS<>1) as t order by t.prices DESC")
    List<MenuFoodItem> listFood(@Param("mfcCode") String mfcCode, @Param("canci") String canci, @Param("nowTime") String nowTime);


    @Select("SELECT * from ( select a.NAME_ZH,a.NAME_EN,b.PRICE as prices ,a.ID,b.ID as priceId, b.BUSINESS_TYPE_ID as businessTypeId " +
            "FROM menu_food_category mfc inner join menu_food_item A on mfc.ID=A.FOOD_CATEGORY_ID " +
            "left join MENU_FOOD_PRICE B on A.ID=B.FOOD_ID " +
            "left join CONFIG_MEAL_TIME c on B.MEAL_TIME_ID = c.ID " +
            "left join CONFIG_BUSINESS_TYPE d on b.BUSINESS_TYPE_ID=d.ID " +
            "where FOOD_CATEGORY_ID = #{categoryId} and (c.NAME= #{canci} or c.Name='全天餐次') and (b.START_TIME<= #{nowTime} and b.END_TIME>= #{nowTime}) and B.STATUS<>1 and A.STATUS<>1 order by B.PRICE DESC) as t order by t.NAME_ZH asc")
    List<MenuFoodItem> listFoodByCategory(@Param("categoryId") String categoryId, @Param("canci") String canci, @Param("nowTime") String nowTime);

}
